const rp = require('request-promise');

module.exports = class extends think.Service {
  async sendSms(phone, code) {
    const sendOptions = {
      method: 'POST',
      url: 'https://cdcxdxjk.market.alicloudapi.com/chuangxin/dxjk',
      headers: {
        Authorization: 'APPCODE 0b6179270deb4582a54b791e35bed469'
      },
      qs: {
        content: `【北京中算】您的验证码是：${'' + code}，3分钟内有效！欢迎您访问北京中算外贸综合服务平台。`,
        mobile: phone
      }
    };

    try {
      const requestResult = await rp(sendOptions);
      if (think.isEmpty(requestResult)) {
        return false;
      }

      return requestResult;
    } catch (err) {
      return err;
    }
  }
};
